﻿using System;
using Assets.Scripts.UI.View.Pause;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

namespace SizeboxUI
{
	// Token: 0x020003B1 RID: 945
	public class PauseController : MonoBehaviour
	{
		// Token: 0x0600193D RID: 6461 RVA: 0x0009E828 File Offset: 0x0009CA28
		private void Update()
		{
			if ((Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(ButtonInput.EscapeAlt)) && !this.CloseIfOpen())
			{
				this.OnResumeClick();
			}
			if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && (Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.LeftAlt)) && Input.GetKeyDown(KeyCode.R))
			{
				GlobalPreferences.UIScale.value = 1f;
				UnityEngine.Object.FindObjectOfType<Canvas>().scaleFactor = GlobalPreferences.UIScale.value;
			}
		}

		// Token: 0x0600193E RID: 6462 RVA: 0x0009E8CC File Offset: 0x0009CACC
		private bool CloseIfOpen()
		{
			bool result = false;
			if (this.saveMenu.activeSelf)
			{
				this.saveMenu.SetActive(false);
				result = true;
			}
			if (this.raygunSettings.activeSelf)
			{
				this.raygunSettings.SetActive(false);
				this.gameSettings.SetActive(true);
				return true;
			}
			if (this.aiGunSettings.activeSelf)
			{
				this.aiGunSettings.SetActive(false);
				this.gameSettings.SetActive(true);
				return true;
			}
			if (this.gameSettings.activeSelf)
			{
				this.gameSettings.SetActive(false);
				result = true;
			}
			if (this.videoSettings.activeSelf)
			{
				this.videoSettings.SetActive(false);
				result = true;
			}
			if (this.audioSettings.activeSelf)
			{
				this.audioSettings.SetActive(false);
				result = true;
			}
			if (this.cloudSettings.activeSelf)
			{
				this.cloudSettings.SetActive(false);
				result = true;
			}
			if (this.lighting.activeSelf)
			{
				this.lighting.SetActive(false);
				result = true;
			}
			if (this.behaviorManager.activeSelf)
			{
				this.behaviorManager.SetActive(false);
				result = true;
			}
			return result;
		}

		// Token: 0x0600193F RID: 6463 RVA: 0x0009EA04 File Offset: 0x0009CC04
		private void Start()
		{
			this.buttonPrefab = Resources.Load<Button>("UI/Pause/PauseButton");
			GameObject original = Resources.Load<GameObject>("UI/BehaviorMgr/BehaviorManagementMenu");
			GameObject original2 = Resources.Load<GameObject>("UI/Pause/SettingsMenu");
			GameObject original3 = Resources.Load<GameObject>("UI/Pause/SaveMenu");
			GameObject original4 = Resources.Load<GameObject>("UI/Pause/CloudMenu");
			this.behaviorManager = UnityEngine.Object.Instantiate<GameObject>(original);
			this.behaviorManager.transform.SetParent(base.transform, false);
			this.behaviorManager.AddComponent<BehaviorManagerView>();
			this.behaviorManager.SetActive(false);
			this.saveMenu = UnityEngine.Object.Instantiate<GameObject>(original3);
			this.saveMenu.transform.SetParent(base.transform, false);
			this.saveMenu.AddComponent<SaveMenuView>();
			this.saveMenu.SetActive(false);
			this.raygunSettings = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.raygunSettings.transform.SetParent(base.transform, false);
			RaygunSettingsView raygunSettingsView = this.raygunSettings.AddComponent<RaygunSettingsView>();
			this.raygunSettings.SetActive(false);
			this.aiGunSettings = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.aiGunSettings.transform.SetParent(base.transform, false);
			AIGunSettingsView aigunSettingsView = this.aiGunSettings.AddComponent<AIGunSettingsView>();
			this.aiGunSettings.SetActive(false);
			this.gameSettings = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.gameSettings.transform.SetParent(base.transform, false);
			this.gameSettings.AddComponent<GameSettingsView>().RaygunSettings = this.raygunSettings;
			this.gameSettings.GetComponent<GameSettingsView>().AIGunSettings = this.aiGunSettings;
			this.gameSettings.SetActive(false);
			raygunSettingsView._gameSettings = this.gameSettings;
			aigunSettingsView._gameSettings = this.gameSettings;
			this.videoSettings = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.videoSettings.transform.SetParent(base.transform, false);
			this.videoSettings.AddComponent<VideoSettingsView>().main = this.main;
			this.videoSettings.SetActive(false);
			this.audioSettings = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.audioSettings.transform.SetParent(base.transform, false);
			this.audioSettings.AddComponent<AudioSettingsView>();
			this.audioSettings.SetActive(false);
			this.cloudSettings = UnityEngine.Object.Instantiate<GameObject>(original4);
			this.cloudSettings.transform.SetParent(base.transform, false);
			this.cloudSettings.AddComponent<CloudSettingsView>();
			this.cloudSettings.SetActive(false);
			this.lighting = UnityEngine.Object.Instantiate<GameObject>(original2);
			this.lighting.transform.SetParent(base.transform, false);
			this.lighting.AddComponent<LightingView>();
			this.lighting.SetActive(false);
			this.buttonLayout = base.gameObject.GetComponentInChildren<GridLayoutGroup>();
			this.AddButton("Resume").onClick.AddListener(delegate()
			{
				this.OnResumeClick();
			});
			this.AddButton("Restart").onClick.AddListener(delegate()
			{
				this.OnResetClick();
			});
			this.AddButton("Save").onClick.AddListener(delegate()
			{
				this.OnSaveClick();
			});
			this.AddButton("Settings").onClick.AddListener(delegate()
			{
				this.OnSettingsClick();
			});
			this.AddButton("Video").onClick.AddListener(delegate()
			{
				this.OnVideoClick();
			});
			this.AddButton("Lighting").onClick.AddListener(delegate()
			{
				this.OnLightingClick();
			});
			this.AddButton("Audio").onClick.AddListener(delegate()
			{
				this.OnAudioClick();
			});
			this.AddButton("Advanced Clouds").onClick.AddListener(delegate()
			{
				this.OnCloudsClick();
			});
			this.AddButton("Main Menu").onClick.AddListener(delegate()
			{
				this.OnMainMenuClick();
			});
			this.AddButton("Quit Game").onClick.AddListener(delegate()
			{
				this.OnQuitClick();
			});
		}

		// Token: 0x06001940 RID: 6464 RVA: 0x0009EE01 File Offset: 0x0009D001
		private void OnEnable()
		{
			Debug.Log("Game paused");
			Cursor.lockState = CursorLockMode.None;
		}

		// Token: 0x06001941 RID: 6465 RVA: 0x0009EE13 File Offset: 0x0009D013
		private void OnDisable()
		{
			Debug.Log("Game resumed");
			if (this.main.mode == MainView.Mode.Play)
			{
				Cursor.lockState = CursorLockMode.Locked;
			}
		}

		// Token: 0x06001942 RID: 6466 RVA: 0x0009EE38 File Offset: 0x0009D038
		private Button AddButton(string label)
		{
			Button button = UnityEngine.Object.Instantiate<Button>(this.buttonPrefab);
			button.transform.SetParent(this.buttonLayout.transform, false);
			button.gameObject.GetComponent<Text>().text = label;
			return button;
		}

		// Token: 0x06001943 RID: 6467 RVA: 0x0009EE7A File Offset: 0x0009D07A
		public void SetGameController(GameController gc)
		{
			this.gameController = gc;
		}

		// Token: 0x06001944 RID: 6468 RVA: 0x0009EE83 File Offset: 0x0009D083
		public void OnResumeClick()
		{
			this.main.ClosePauseMenu();
		}

		// Token: 0x06001945 RID: 6469 RVA: 0x0009EE90 File Offset: 0x0009D090
		public void OnBehaviorManagerClicked()
		{
			this.behaviorManager.SetActive(true);
		}

		// Token: 0x06001946 RID: 6470 RVA: 0x0009EE9E File Offset: 0x0009D09E
		public void OnResetClick()
		{
			SavedScenesManager.Instance.RestartScene();
		}

		// Token: 0x06001947 RID: 6471 RVA: 0x0009EEAA File Offset: 0x0009D0AA
		public void OnSaveClick()
		{
			this.saveMenu.SetActive(true);
		}

		// Token: 0x06001948 RID: 6472 RVA: 0x0009EEB8 File Offset: 0x0009D0B8
		public void OnSettingsClick()
		{
			this.gameSettings.SetActive(true);
		}

		// Token: 0x06001949 RID: 6473 RVA: 0x0009EEC6 File Offset: 0x0009D0C6
		public void OnAudioClick()
		{
			this.audioSettings.SetActive(true);
		}

		// Token: 0x0600194A RID: 6474 RVA: 0x0009EED4 File Offset: 0x0009D0D4
		public void OnVideoClick()
		{
			this.videoSettings.SetActive(true);
		}

		// Token: 0x0600194B RID: 6475 RVA: 0x0009EEE2 File Offset: 0x0009D0E2
		public void OnCloudsClick()
		{
			this.cloudSettings.SetActive(true);
		}

		// Token: 0x0600194C RID: 6476 RVA: 0x0009EEF0 File Offset: 0x0009D0F0
		public void OnLightingClick()
		{
			this.lighting.SetActive(true);
		}

		// Token: 0x0600194D RID: 6477 RVA: 0x0009EEFE File Offset: 0x0009D0FE
		public void CloseSettings()
		{
			this.gameSettings.SetActive(false);
		}

		// Token: 0x0600194E RID: 6478 RVA: 0x0009EF0C File Offset: 0x0009D10C
		public void OnMainMenuClick()
		{
			this.gameController.SetPausedState(false);
			NetworkManager.singleton.StopHost();
			SceneManager.LoadScene("MainMenu");
		}

		// Token: 0x0600194F RID: 6479 RVA: 0x0009EF2E File Offset: 0x0009D12E
		public void OnQuitClick()
		{
			NetworkManager.singleton.StopHost();
			Application.Quit();
		}

		// Token: 0x04001B57 RID: 6999
		public MainView main;

		// Token: 0x04001B58 RID: 7000
		private GameController gameController;

		// Token: 0x04001B59 RID: 7001
		private GameObject behaviorManager;

		// Token: 0x04001B5A RID: 7002
		private GameObject gameSettings;

		// Token: 0x04001B5B RID: 7003
		private GameObject videoSettings;

		// Token: 0x04001B5C RID: 7004
		private GameObject audioSettings;

		// Token: 0x04001B5D RID: 7005
		private GameObject saveMenu;

		// Token: 0x04001B5E RID: 7006
		private GameObject cloudSettings;

		// Token: 0x04001B5F RID: 7007
		private GameObject lighting;

		// Token: 0x04001B60 RID: 7008
		private GameObject raygunSettings;

		// Token: 0x04001B61 RID: 7009
		private GameObject aiGunSettings;

		// Token: 0x04001B62 RID: 7010
		private Button buttonPrefab;

		// Token: 0x04001B63 RID: 7011
		private GridLayoutGroup buttonLayout;
	}
}
